// pages/draw/fillAddr/index.js
var common = require("../../../public.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: '',
    token: '',
    mainImage: '',
    orderId: '',
    storeAddress: '',
    storePhone: '',
    title: '',
    receiverName: '',
    receiverMobile: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(JSON.parse(decodeURIComponent(options.parames)))
    let that = this
    let opt = JSON.parse(decodeURIComponent(options.parames))
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
          mainImage: opt.mainImage,
          awardName:opt.awardName,
          orderId: opt.orderId,
          storeAddress: opt.storeAddress,
          storePhone: opt.storePhone,
          title: opt.title
        })
      }
    })
  },
  commit() {

    let that = this
    let {
      receiverName,
      receiverMobile,
      orderId,
      token
    } = that.data
    if (!receiverName) {
      common.showToast('请填写提货人姓名')
      return
    }
    if (!receiverMobile) {
      common.showToast('请填写提货人手机')
      return
    }
    let tempJson = {
      token,
      userId: that.data.userInfo.id,
      orderId,
      receiverName,
      receiverMobile,
    }
    common.post("/storeDraw/saveStoreDrawWinnerInfo", tempJson, function (res) {
      if (res.status == 200) {
        common.showToast('提交成功')
        wx.navigateBack({
          delta: 1,
        })
      } else {
        common.showRequestErrMsg(res)
      }
    })
  },
  changeReceiverName(e) {
    this.setData({
      receiverName: e.detail
    })

  },
  changeReceiverMobile(e) {
    this.setData({
      receiverMobile: e.detail
    })
  }
})